home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 571 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.5 KB  |  71 lines

  1. Path: gate.net!pslfl2-40
  2. From: bhutto@gate.net (William Hutto)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Q: Terminating program at EOF
  5. Date: 7 Jan 1996 04:40:33 GMT
  6. Organization: CyberGate, Inc.
  7. Message-ID: <4cnis1$1plk@news.gate.net>
  8. References: <4cn66j$5r0@fnpx20.fnal.gov>
  9. NNTP-Posting-Host: pslfl2-40.gate.net
  10. X-Newsreader: News Xpress Version 1.0 Beta #4
  11.  
  12. In article <4cn66j$5r0@fnpx20.fnal.gov>,
  13.    sfield@fnpx20.fnal.gov (Stephen Field) wrote:
  14. >Hi,
  15. >
  16. >I'm writing a program that looks at poorly formatted text files and reformats
  17. >them to a user-specified line length. The input text file has a blank line
  18. >between paragraphs and I would like the newly formatted file to also have 
  19. blank
  20. >lines between paragraphs.
  21. >
  22. >I've written a program that does the job, but it doesn't stop when it reaches
  23. >the end of the file. The program will write out the reformatted file, but it
  24. >appends a lot of "extra" characters to the end of the file and only stops 
  25. when
  26. >I break out of it.
  27. >
  28. >I have tried this program on many files and it behaves the same. The program
  29. >is included below and I've got it running on an SGI running IRIX.
  30. >
  31. >Any help appreciated.
  32. >
  33. >Steve
  34. >
  35. >===================================================
  36. >/*    This program reformats a file that is input by the user to not exceed
  37. >    a number of columns that is also input and outputs the reformatted 
  38. file
  39. >    to a file also given by the user at runtime. Lines are broken at 
  40. spaces. */
  41. >#include <stdio.h>
  42. >#define MAX_WORD_LENGTH 80    /* max length of word in input */
  43. >
  44. >main()
  45. >{
  46. >  int line_length,        /* max length of line in output */
  47. >      curr_line_length = 0,    /* # of chars printed so far in curr line */
  48. >      word_length;        /* length of current word */
  49. >  char word[ MAX_WORD_LENGTH+1];/* buffer to read word +1 for terminating
  50. >                    '\0' */
  51. >  char c_old=' ',c_new=' ';     /* check for newlines with chars */
  52.    ^^^^
  53. Read comp.lang.c FAQ 12.1. An EOF won't fit in a *char*. Change this to *int*. 
  54.  
  55. >    while(c_new!=EOF){                       /* new method, still doesn't 
  56. work */
  57. >      c_new=fgetc(fptr_read);
  58.  
  59. The flow of your code is difficult to follow (not using the _standard_ tabbing 
  60. for nested blocks). I would be surprised if anybody would want to spend their 
  61. time looking at it. If you want such generous commenting in your code and you 
  62. don't want to exceed some right margin, I would suggest you put comments on 
  63. separate lines preceding the fragment of code it refers to.
  64.  
  65. You can get the FAQ from:
  66. ftp://rtfm.mit.edu/pub/usenet-by-group/comp.lang.c/C-FAQ-list
  67.  
  68. Bill
  69.  
  70. "Whatcha got on?...Your mind?"
  71.